package com.itheima.hello.hellopromax高级进阶.囚犯排队案例;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class test {
    public static void main(String[] args) {
        ArrayList<Integer> people = new ArrayList<>();
        Random r = new Random();
        for (int i = 0; i < 100; i++) {
            int p = r.nextInt(1,201);
            if (people.contains(p)) {
                i--;
                continue;
            }else {
                people.add(p);
            }
        }
        System.out.println(people);
        ArrayList<Integer> people2 = new ArrayList<>();
        people2.addAll(people);
//        System.out.println(people2);
//        System.out.println(people2.size());


        while (people.size() > 1){
        ArrayList<Integer> lp = new ArrayList<>();//临时集合
        for (int i = 1; i < people.size(); i+=2) {
                int s = people.get(i);
                lp.add(s);
            }
        people = lp;
        }
//        System.out.println(people);
//        System.out.println(people.size());
        int Luck = people.get(0);
        int index = people2.indexOf(Luck);
//        System.out.println(people);
        System.out.println("幸存者的编号为:" + Luck);
        System.out.println("幸存者原来的位置的值为:" + (index + 1 ));
    }
}
